function whoAnsLike() {
	$(".whoLikeAans").toggle();
	if($(".whoLikeAans").is(':hidden')){
		$('.likeVote ul li:nth-child(2) span').css({
			'background-position':'0 -42px'
		});
	}else{
		findAskLikeUsers();
		findAskReceivedAnswers();
		$('.likeVote ul li:nth-child(2) span').css({
			'background-position':'0 -60px'
		});
	}
}
function findAskLikeUsers() {
	var url = "../like/findAskLikeUsers.action";
	var params = {
		"like.askId" : $("#detailDiv").attr("askId")
	};
	doAjaxHtml(url, params, function(response) {
				if (response) {
					$(".whoLike").html(response);
					$('.whoTitle h3 a.shut').click(function(){
						$(".whoLikeAans").hide();
					});
				}
			});
}

function findAskComments() {
	var url = "../comment/findAskComments.action";
	var params = {
		"query.askId" : $("#detailDiv").attr("askId")
	};
	doAjaxHtml(url, params, function(response) {
				if (response) {
					$(".askDiss").html(response);
					$(".disReplay ").click(registReplyEvent);
					registLikeCommentEvent();
				}
			});
}

function findAskReceivedAnswers(page){
	var askId= $("#detailDiv").attr("askId");
	var url="../answer/findAskReceivedAnswers.action";
	var params={
			"query.askId":askId,
			"query.toPage":page
	};
	doAjaxHtml(url,params,function(response){
		$(".whoAans").html("");
		$(".whoAans").append(response);
		padFollow();
	});
	
}
function padFollow(){
	$(".follow").click(function(){
		if($(this).hasClass("following")){
			var user =  $(this);
			var params = {
					"query.followId" : user.parents("li").attr("userId")
			};
			unFollowUser(params, function(ajaxResult) {
						if (ajaxResult.OK) {
							user.removeClass("following").text("关注");
							user.unbind().click(regMyFollow);
						}
					})
		}
		else{
			var user = $(this);
			var params = {
				"query.followId" : user.parents("li").attr("userId")
			};
			followUser(params, function(ajaxResult) {
						if (ajaxResult.OK) {
							user.addClass("following").text("取消关注");
							user.unbind().click(regMyUnFollow);
						}
					})
		}
	});
}
function regMyFollow() {
	var user = $(this);
	var params = {
		"query.followId" : user.parents("li").attr("userId")
	};
	followUser(params, function(ajaxResult) {
				if (ajaxResult.OK) {
					user.addClass("following").text("取消关注");
					user.unbind().click(regMyUnFollow);
				}
			})
}
function regMyUnFollow() {
	var user =  $(this);
	var params = {
			"query.followId" : user.parents("li").attr("userId")
	};
	unFollowUser(params, function(ajaxResult) {
				if (ajaxResult.OK) {
					user.removeClass("following").text("关注");
					user.unbind().click(regMyFollow);
				}
			})
}

//添加评论
function addComment(){
	var askId=$("#detailDiv").attr("askId");
	var comment = $.trim($(".addDissArea").val());
	var url="../commentAjax/addComment.action";
	if(comment == ''){
		alertTipDown("请输入评论内容","cuo");
		alertTipUp();
		return false;
	}
	var params={
			"comment.askId" :askId,
			"comment.commentBody" :comment
			
	};
	doAjax(url,params,function(ajaxResult){
		if (ajaxResult.OK) {
			//alertTipDown("评论成功","dui");
			$(".addDissArea").val("");
			$('#commentTextDiv .txt_count span').text(0);
			findAskComments();
		}else{
			alertTipDown(ajaxResult.message,"cuo");
		}
	});
	
}
function registReplyEvent(){
	var obj =$(this);
	var loginName=obj.parents(".askDissDl ").find(".ownerName").text();
	var valueStr = "@" + $.trim(loginName) + "-";
	$("#txt002").val(valueStr).focus();;
}
function registLikeCommentEvent(){
	$(".delLike").click(deleteCommnetDitto);
	$(".addLike").click(addCommnetDitto);
}
//添加同意评论观点
function addCommnetDitto(){
	var obj =$(this);
	var commentId=obj.parents(".askDissDl").attr("commentId");
	var url="../commentDittoAjax/addCommentDitto.action";
	var params={
			"commentDitto.commentId" :commentId
	};
	doAjax(url,params,function(ajaxResult){
		if(ajaxResult.OK){
			alertTipDown("成功","dui");
			var dittoCount = parseInt(obj.find("em").html())+ 1;
			obj.parent("dd").find(".delLike em").html(dittoCount);
			obj.parent("dd").find(".delLike").show();
			obj.hide();
		}
		else{
			alertTipDown("系统繁忙","cuo");
		}
	});
}
//取消同意评论观点
function deleteCommnetDitto(){
	var obj =$(this);
	var commentId=obj.parents(".askDissDl").attr("commentId");
	var url="../commentDittoAjax/deleteCommentDitto.action";
	var params={
			"commentDitto.commentId" :commentId
	};
	doAjax(url,params,function(ajaxResult){
		if(ajaxResult.OK){
			alertTipDown("成功","dui");
			var dittoCount = parseInt(obj.find("em").html())-1;
			obj.parent("dd").find(".addLike em").html(dittoCount);
			obj.parent("dd").find(".addLike").show();
			obj.hide();
		}
		else{
			alertTipDown("系统繁忙","cuo");
		}
	});
}